<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <!-- import CSS -->
  <link rel="stylesheet" href="https://cdn.staticfile.org/element-ui/2.15.9/theme-chalk/index.css">
</head>
<body>
<div id="app">
  <h1>微博首页</h1>
  <div v-if="isLogin">
    <h1>欢迎回来！{{user.nickname}}</h1>
    <a href="/insert.html">发微博</a>
    <a href="/myList.html">我的微博</a>
    <a href="javascript:void(0)" @click="logout()">退出登录</a>
  </div>
  <div v-else>
    <a href="/reg.html">注册</a>
    <a href="/login.html">登录</a>
  </div>
  <hr>
  <div v-for="weibo in arr">
    <a :href="'/detail.html?id='+weibo.id">
      <h3>{{weibo.nickname}} 说：{{weibo.content}}</h3>
    </a>
  </div>

</div>
</body>
<script src="https://cdn.bootcdn.net/ajax/libs/axios/0.21.1/axios.min.js"></script>
<!-- import Vue before Element -->
<script src="https://cdn.staticfile.org/vue/2.6.14/vue.min.js"></script>
<!-- import JavaScript -->
<script src="https://cdn.staticfile.org/element-ui/2.15.9/index.min.js"></script>
<script>
 let v = new Vue({
    el: '#app',
    data: function() {
      return {
        user:{},
        isLogin:false,
        arr:[]
      }
    },
    methods:{
      logout(){
        if(confirm("您确定退出登录么？")){
          axios.get("/user/logout").then(function (response) {
              v.isLogin = false;
          })
        }
      }
    },
   created:function () {
     axios.get("/weibo/select").then(function (response) {
       v.arr = response.data;
     })

     axios.get("/user/currentUser").then(function (response) {
       if(response.data==""){
         v.isLogin = false;
       }else{
         v.isLogin = true;
         v.user = response.data;
       }
     })
   }
  })
</script>
</html>